﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class LoaiKhachHangDAO
    {
        public static DataTable GetAll()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select * From LoaiKhach";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable LoaiKhachTheoTen(string ten)
        {
            DataProvider dp = new DataProvider();
            string sql = "Select MaLoaiKhach From LOAIKHACH Where TenLoaiKhach like " + ten + "";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable HeSoLoaiKhachTheoMaLoai(int ma)
        {
            DataProvider dp = new DataProvider();
            string sql = "Select HeSoLoaiKhach From LoaiKhach Where MaLoaiKhach = " + ma + "";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static void ThemLoaiKhach(LoaiKhachHangDTO lk)
        {
            string sql = string.Format("INSERT INTO LoaiKhach(MaLoaiKhach, TenLoaiKhach, HeSoLoaiKhach) VALUES (" + lk.MaLoaiKhach + ",'" + lk.TenLoaiKhach + "'," + lk.HeSoLoaiKhach + ")");
            DataProvider.ExecuteNonQuery(sql);
        }

        public static void CapNhatLoaiKhach(LoaiKhachHangDTO lk)
        {
            string sql = string.Format("Update LoaiKhach Set TenLoaiKhach = N'" + lk.TenLoaiKhach + "', HeSoLoaiKhach = " + lk.HeSoLoaiKhach + " Where MaLoaiKhach = " + lk.MaLoaiKhach + "");
            DataProvider.ExecuteNonQuery(sql);
        }

        public static void XoaLoaiKhach(int maloaikhach)
        {
            string sql = string.Format("Delete From LoaiKhach Where MaLoaiKhach = " + maloaikhach + "");
            DataProvider.ExecuteNonQuery(sql);
        }
    }
}
